/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cassys.delegates;

import cassys.dataaccess.DAOException;
import cassys.datatransferobjects.ModuleDTO;
import cassys.datatransferobjects.StudentDTO;
import cassys.datatransferobjects.StudentModuleTeamDTO;
import cassys.datatransferobjects.TeamDTO;
import cassys.ejb.sessionbean.StudentBeanRemote;
import cassys.ejb.sessionbean.StudentModuleTeamBeanRemote;
import cassys.servicelocator.ServiceLocator;
import java.rmi.RemoteException;
import java.util.ArrayList;
import java.util.Iterator;

/**
 *
 * @author ASUS
 */
public class StudentModuleTeamDelegate {

    private StudentModuleTeamBeanRemote stdModTeamBean = null;
    private ModuleDelegate modDelegate;
     private StudentDelegate stdDelegate ;
    private UserDelegate userDelegate;

    public StudentModuleTeamDelegate() {
        stdModTeamBean = (StudentModuleTeamBeanRemote) ServiceLocator.getInstance().lookupStudentModuleTeamBean();
       modDelegate = new ModuleDelegate();
        stdDelegate = new StudentDelegate();
        userDelegate = new UserDelegate();
        
    }
    
    
    /*
    // public void insertStudentModuleTeam(StudentModuleTeamDTO dto){};
    public void updateStatus(String status) {
    }
    
    public void updateGPA(int gpa) {
    }
    
    public StudentDTO getStudent() {
    return null;
    }
    
    public ModuleDTO getModule() {
    return null;
    }
    
    public TeamDTO getTeam() {
    return null;
    }
    
    public ArrayList<StudentDTO> getAllStudentsInTeam(String teamid) {
    return null;
    }
    
    public ArrayList<StudentDTO> getAllStudentsInModule(String moduleid) {
    return null;
    }
    */
   
    /*
    public ArrayList<StudentDTO> getAllModulesforTeam(String studentid) {
    return null;
    }
    
    public ArrayList<StudentDTO> getAllTeamInModule(String moduleid) {
    return null;
    }
     */
    
    public ArrayList<StudentDTO> getAllStudents() throws DAOException, RemoteException {
        ArrayList<StudentModuleTeamDTO> list = findAllStudnetModulTeams();
        ArrayList<StudentDTO> temp = null;
        if (list != null && list.size() > 0) {
            temp = new ArrayList<StudentDTO>();
            Iterator<StudentModuleTeamDTO> iter = list.iterator();
            while (iter.hasNext()) {
                temp.add(stdDelegate.findStudent(iter.next().getStudentId()));
            }
        }
        return temp;

    }
    
    public ArrayList<StudentDTO> getAllStudentsInTeam(String teamId) throws DAOException, RemoteException {
        ArrayList<StudentModuleTeamDTO> list = findAllStudnetModulTeams();
        ArrayList<StudentDTO> temp = null;
        if (list != null && list.size() > 0) {
            temp = new ArrayList<StudentDTO>();
            Iterator<StudentModuleTeamDTO> iter = list.iterator();
            while (iter.hasNext()) {
                StudentModuleTeamDTO dto = iter.next();
                if(dto.getTeamId().equalsIgnoreCase(teamId)){
                    temp.add(stdDelegate.findStudent(dto.getStudentId()));
                }
            }
        }
        return temp;
    }

    public ArrayList<StudentDTO> getAllStudentsInModule(String moduleCode) throws DAOException, RemoteException {
        ArrayList<StudentModuleTeamDTO> list = findAllStudnetModulTeams();
        ArrayList<StudentDTO> temp = null;
        if (list != null && list.size() > 0) {
            temp = new ArrayList<StudentDTO>();
            Iterator<StudentModuleTeamDTO> iter = list.iterator();
            while (iter.hasNext()) {
                StudentModuleTeamDTO dto = iter.next();
                if(dto.getModulecode().equalsIgnoreCase(moduleCode)){
                    temp.add(stdDelegate.findStudent(dto.getStudentId()));
                }
            }
        }
        return temp;
    }

    public ArrayList<StudentModuleTeamDTO> findAllStudnetModulTeams() throws DAOException, RemoteException {
        ArrayList<StudentModuleTeamDTO> list = (ArrayList<StudentModuleTeamDTO>) stdModTeamBean.findAllStudnetModulTeams();
        return list;
    }

    public ArrayList<StudentModuleTeamDTO> findAllStudnetByModule(String moduleCode) throws DAOException, RemoteException {
        ArrayList<StudentModuleTeamDTO> list = (ArrayList<StudentModuleTeamDTO>) stdModTeamBean.findAllStudnetByModule(moduleCode);
        return list;
    }

    public ArrayList<StudentModuleTeamDTO> findAllStudnetByTeam(String teamId) throws DAOException, RemoteException {
        ArrayList<StudentModuleTeamDTO> list = (ArrayList<StudentModuleTeamDTO>) stdModTeamBean.findAllStudnetByTeam(teamId);
        return list;
    }

    public StudentModuleTeamDTO findModule(String moduleCode) throws DAOException, RemoteException {
        return stdModTeamBean.findModule(moduleCode);
    }

    public StudentModuleTeamDTO findStudnet(String studentId) throws DAOException, RemoteException {
        return stdModTeamBean.findStudnet(studentId);
    }

    public StudentModuleTeamDTO findTeam(String teamId) throws DAOException, RemoteException {
        return stdModTeamBean.findTeam(teamId);
    }

    public void insertStudentModuleTeam(StudentModuleTeamDTO stdmodTeam) throws DAOException, RemoteException {
        stdModTeamBean.insertStudentModuleTeam(stdmodTeam);
    }

    public void updateStudentModuleTeam(StudentModuleTeamDTO stdmodTeam) throws DAOException, RemoteException {
        stdModTeamBean.updateStudentModuleTeam(stdmodTeam);
    }

    public void deleteStudentModuleTeam(StudentModuleTeamDTO stdmodTeam) throws DAOException, RemoteException {
        stdModTeamBean.deleteStudentModuleTeam(stdmodTeam);
    }
}
